<template>
  <el-input v-model="codeNum" :disabled="disabled" :placeholder="placeholder">
    <template #append>
      <el-button
        :loading="loading"
        :disabled="disabled"
        loading-icon="Tools"
        icon="Tools"
        @click="createNum"
        >系统编号</el-button
      >
    </template>
  </el-input>
</template>

<script setup name="CodeInput">
import { doCreateNum } from "@/api/system/createNum";
import { debounce } from "@/utils";
const props = defineProps({
  code: {
    type: String,
    default: "",
    required: true,
  },
  disabled: {
    type: Boolean,
    default: false,
  },
  placeholder: {
    type: String,
    default: "请输入编号",
  },
});
const { placeholder, code, disabled } = toRefs(props);
const codeNum = defineModel();
const loading = ref(false);
const createNum = debounce(() => {
  if (disabled.value) return;
  if (!code.value) return;
  loading.value = true;
  doCreateNum(code.value)
    .then((res) => {
      codeNum.value = res.data;
      loading.value = false;
    })
    .catch(() => {
      loading.value = false;
    });
}, 500);
</script>

<style lang="scss" scoped></style>
